package org.kele.k8s.sc2020.config;

import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.id.SaIdUtil;
import cn.dev33.satoken.util.SaResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Sa-Token 权限认证 配置类
 */
@Slf4j
@Configuration
public class SaTokenCheckConfigure implements WebMvcConfigurer {

    @Bean
    public SaServletFilter getSaServletFilter() {
        log.info("===== 拦截request 校验内部请求");
        return new SaServletFilter()
                .addInclude("/**")
                .addExclude("/favicon.ico")
                .setAuth(obj -> SaIdUtil.checkCurrentRequestToken())
                .setError(e -> {
                    log.error("check inside failed....{}", e.getMessage());
                    return SaResult.error(e.getMessage());
                });
    }

}

